package com.lianniu.web.demand.service.impl;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.demand.dao.DemandSupplyDao;
import com.lianniu.web.demand.service.DemandService;
import com.lianniu.web.demand.service.DemandSupplyService;
import com.lianniu.web.demand.vo.DemandSupplyVo;
import com.lianniu.web.demand.vo.DemandVo;
import com.lianniu.web.product.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017-05-15.
 */
@Service
public class DemandSupplyServiceImpl implements DemandSupplyService{
    @Autowired
    DemandSupplyDao demandSupplyDao;

    @Autowired
    DemandService demandService;
    @Override
    public BaseResult insertSelective(DemandSupplyVo record) {
        int in = this.demandSupplyDao.insertSelective(record);
        return BaseResult.success(in);
    }

    @Override
    public BaseResult selectByPrimaryKey(Long id) {
        DemandSupplyVo demandSupplyVo = this.demandSupplyDao.selectByPrimaryKey(id);
        return BaseResult.success(demandSupplyVo);
    }

    @Override
    public BaseResult updateByPrimaryKeySelective(DemandSupplyVo record) {
        int up = this.demandSupplyDao.updateByPrimaryKeySelective(record);
        return BaseResult.success(up);
    }

    @Override
    public BaseResult selectByUserId(String userId, int pageNum) {
        int count = this.demandSupplyDao.selectByUserIdCount(userId);
        Page page = new Page(count, pageNum);
        List<DemandSupplyVo> list = this.demandSupplyDao.selectByUserId(userId, page);
        for (DemandSupplyVo demandSupplyVo : list) {
            DemandVo demandVo = (DemandVo)this.demandService.selectByPrimaryKey(demandSupplyVo.getDemandid()).getData();
            demandSupplyVo.setDemandVo(demandVo);
        }
        return BaseResult.success(list);
    }
}
